package com.hsc.yalebao.tabIndex;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hsc.pcddfivepcdd.R;
import com.hsc.yalebao.adapter.AdvViewPagerAdapter;
import com.hsc.yalebao.base.ActivityStack;
import com.hsc.yalebao.base.BaseFragment;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.base.MainActivity;
import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.http.RequestNet;
import com.hsc.yalebao.model.AvdBaseModel;
import com.hsc.yalebao.model.AvdModel;
import com.hsc.yalebao.model.NumberModel;
import com.hsc.yalebao.model.RoomListBaseBean;
import com.hsc.yalebao.model.RoomListBean;
import com.hsc.yalebao.tabMine.WanFaActivity;
import com.hsc.yalebao.tools.UiUtil;
import com.hsc.yalebao.weight.LogUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

import okhttp3.Call;

@SuppressLint({"NewApi"})
public class IndexFragment extends BaseFragment
        implements View.OnClickListener {
    public static String bjStr = "";
    public static String canStr = "";
    public static IndexFragment fragment;
    private String TAG = "IndexFragment";
    String canadaLotteryId;
    String canadaRoomId;
    private View contentView;
    private int currentItem = 0;
    private ArrayList<ImageView> dot_view;
    private Handler handler = new Handler() {
        public void handleMessage(Message paramAnonymousMessage) {
            if ((IndexFragment.this.viewPager != null) && (IndexFragment.this.pic_ids != null) && (IndexFragment.this.pic_ids.size() != 0)) {
                IndexFragment.this.currentItem = ((1 + IndexFragment.this.viewPager.getCurrentItem()) % IndexFragment.this.pic_ids.size());
                IndexFragment.this.viewPager.setCurrentItem(IndexFragment.this.currentItem);
            }
            LogUtils.i(IndexFragment.this.TAG, "currentItem:" + IndexFragment.this.currentItem);
        }
    };
    private ImageView img;
    private ImageView img_scroll_left;
    private ImageView img_scroll_right;
    private ImageView img_wanfa_canada;
    private ImageView img_wanfa_paking;
    private boolean isRunning = true;
    private LinearLayout layout_dots;
    private RelativeLayout lin_canda_28;
    private RelativeLayout lin_paking_28;
    private LinearLayout lin_rooms;
    private AdvViewPagerAdapter pagerAdapter;
    String pakingLotteryId;
    String pakingRoomId;
    public ArrayList<AvdBaseModel> pic_ids;
    private int screenHeight = 0;
    private int screenWidth = 0;
    private Timer timer = new Timer();
    private AdvTimerTask timerTask;
    private TextView tv_earn_money_index;
    private TextView tv_register_people_count;
    private TextView tv_zhuanqian_percent;
    private ViewPager viewPager;
    private WindowManager windowManager;

    private void getBanners() {
        HashMap localHashMap = new HashMap();
        localHashMap.put("Type", "1");
        localHashMap.put("num", "10");
        RequestNet.get(getActivity(), AppConstants.URL_GET_AD_LIST, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                LogUtils.e(IndexFragment.this.TAG, "获取失败,获取banner:" + paramAnonymousException);
            }

            public void onResponse(String paramAnonymousString) {
                LogUtils.d(IndexFragment.this.TAG, "result:" + paramAnonymousString);
                Gson localGson = new Gson();
                try {
                    localAvdModel = (AvdModel) localGson.fromJson(paramAnonymousString, AvdModel.class);
                    if (localAvdModel == null) {
                        LogUtils.e(IndexFragment.this.TAG, "获取失败");
                        return;
                    }
                } catch (Exception localException) {
                    AvdModel localAvdModel;
                    do {
                        while (true) {
                            localException.printStackTrace();
                            localAvdModel = null;
                        }
                        if (localAvdModel.getFlag() == -4) {
                            ActivityStack.getInstance().backToMain(MainActivity.class, IndexFragment.this.getActivity());
                            return;
                        }
                        if (localAvdModel.getFlag() == 0) {
                            UiUtil.showToast(IndexFragment.this.getActivity(), localAvdModel.getMsg());
                            return;
                        }
                        if (localAvdModel.getFlag() == -2) {
                            MainActivity.mainActivity.showOffLineDialog();
                            return;
                        }
                        if (localAvdModel.getFlag() == -3) {
                            MainActivity.mainActivity.showFengjinDialog();
                            return;
                        }
                    }
                    while (localAvdModel.getFlag() != 1);
                    IndexFragment.this.pic_ids = localAvdModel.getResult();
                    IndexFragment.this.initDotsAndMakeStart();
                }
            }
        });
    }

    private void getNumberInfo() {
        HashMap localHashMap = new HashMap();
        LogUtils.i(this.TAG, "getNumberInfo()-Url:" + AppConstants.URL_GET_CONFIG);
        RequestNet.get(getActivity(), AppConstants.URL_GET_CONFIG, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                Log.e(IndexFragment.this.TAG, "获取失败,获取首页注册人数 赚钱率:" + paramAnonymousException);
            }

            public void onResponse(String paramAnonymousString) {
                LogUtils.d(IndexFragment.this.TAG, "result:" + paramAnonymousString);
                if ((paramAnonymousString == null) || ("".equals(paramAnonymousString)))
                    return;
                Gson localGson = new Gson();
                try {
                    localNumberModel = (NumberModel) localGson.fromJson(paramAnonymousString, NumberModel.class);
                    if (localNumberModel == null) {
                        LogUtils.e(IndexFragment.this.TAG, "获取失败");
                        return;
                    }
                } catch (Exception localException) {
                    NumberModel localNumberModel;
                    while (true) {
                        localException.printStackTrace();
                        localNumberModel = null;
                    }
                    if (localNumberModel.getFlag() == -4) {
                        ActivityStack.getInstance().backToMain(MainActivity.class, IndexFragment.this.getActivity());
                        return;
                    }
                    if (localNumberModel.getFlag() == 1) {
                        int i = localNumberModel.getReg_num();
                        double d1 = localNumberModel.getEarn_total();
                        double d2 = localNumberModel.getEarn_rate();
                        IndexFragment.this.tv_earn_money_index = ((TextView) IndexFragment.this.contentView.findViewById(2131100101));
                        IndexFragment.this.tv_register_people_count = ((TextView) IndexFragment.this.contentView.findViewById(2131100102));
                        IndexFragment.this.tv_zhuanqian_percent = ((TextView) IndexFragment.this.contentView.findViewById(2131100103));
                        IndexFragment.this.tv_earn_money_index.setText((int) d1 + "元宝");
                        IndexFragment.this.tv_register_people_count.setText(i + "人");
                        IndexFragment.this.tv_zhuanqian_percent.setText((int) (100.0D * d2));
                        IndexFragment.this.tv_earn_money_index.setTextColor(IndexFragment.this.getResources().getColor(2131165336));
                        IndexFragment.this.tv_register_people_count.setTextColor(IndexFragment.this.getResources().getColor(2131165336));
                        return;
                    }
                    if (localNumberModel.getFlag() == -2) {
                        MainActivity.mainActivity.showOffLineDialog();
                        return;
                    }
                    UiUtil.showToast(IndexFragment.this.getActivity(), localNumberModel.getMsg());
                }
            }
        });
    }

    private void getParent0RoomListInfo() {
        HashMap localHashMap = new HashMap();
        localHashMap.put("parentID", "0");
        localHashMap.put("lottery_id", "0");
        LogUtils.i(this.TAG, "getParent0RoomListInfo()-Url:" + AppConstants.URL_GET_ROOMBYPARENTID);
        RequestNet.get(getActivity(), AppConstants.URL_GET_ROOMBYPARENTID, localHashMap, new StringCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                LogUtils.e(IndexFragment.this.TAG, "获取失败,getParent1RoomListInfo-result:" + paramAnonymousException);
            }

            public void onResponse(String paramAnonymousString) {
                LogUtils.d(IndexFragment.this.TAG, "result:" + paramAnonymousString);
                Gson localGson = new Gson();
                try {
                    localRoomListBean = (RoomListBean) localGson.fromJson(paramAnonymousString, RoomListBean.class);
                    if (localRoomListBean == null) {
                        LogUtils.e(IndexFragment.this.TAG, "获取失败");
                        return;
                    }
                } catch (Exception localException) {
                    RoomListBean localRoomListBean;
                    ArrayList localArrayList;
                    do {
                        while (true) {
                            localException.printStackTrace();
                            localRoomListBean = null;
                        }
                        if (localRoomListBean.getFlag() == -4) {
                            ActivityStack.getInstance().backToMain(MainActivity.class, IndexFragment.this.getActivity());
                            return;
                        }
                        if (localRoomListBean.getFlag() != 1)
                            break;
                        localArrayList = localRoomListBean.getResult();
                    }
                    while ((localArrayList == null) || (localArrayList.size() <= 0));
                    for (int i = 0; i < localArrayList.size(); i++) {
                        RoomListBaseBean localRoomListBaseBean = (RoomListBaseBean) localArrayList.get(i);
                        if (localRoomListBaseBean != null) {
                            String str = localRoomListBaseBean.getTitle();
                            localRoomListBaseBean.getOnline_num();
                            int j = localRoomListBaseBean.getId();
                            int k = localRoomListBaseBean.getLottery_id();
                            if ("北京快乐28".equals(str)) {
                                IndexFragment.this.pakingRoomId = j;
                                IndexFragment.this.pakingLotteryId = k;
                            }
                            if ("加拿大28".equals(str)) {
                                IndexFragment.this.canadaRoomId = j;
                                IndexFragment.this.canadaLotteryId = k;
                            }
                        }
                    }
                    if (localRoomListBean.getFlag() == -2) {
                        MainActivity.mainActivity.showOffLineDialog();
                        return;
                    }
                    UiUtil.showToast(IndexFragment.this.getActivity(), localRoomListBean.getMsg());
                }
            }
        });
    }

    private void init() {
        this.pic_ids = new ArrayList();
        this.dot_view = new ArrayList();
        this.layout_dots = ((LinearLayout) this.contentView.findViewById(R.id.layout_dots));
        this.viewPager = ((ViewPager) this.contentView.findViewById(R.id.viewPager));
        if (this.pagerAdapter == null)
            this.pagerAdapter = new AdvViewPagerAdapter(this.pic_ids, getActivity());
        this.viewPager.setAdapter(this.pagerAdapter);
        this.viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            int oldPosition = 0;

            public void onPageScrollStateChanged(int paramAnonymousInt) {
                LogUtils.d("onPageScrollStateChanged", "arg0:" + paramAnonymousInt);
            }

            public void onPageScrolled(int paramAnonymousInt1, float paramAnonymousFloat, int paramAnonymousInt2) {
            }

            public void onPageSelected(int paramAnonymousInt) {
                if (IndexFragment.this.isRunning) {
                    ((ImageView) IndexFragment.this.dot_view.get(this.oldPosition)).setImageResource(2130838124);
                    ((ImageView) IndexFragment.this.dot_view.get(paramAnonymousInt)).setImageResource(2130838125);
                    this.oldPosition = paramAnonymousInt;
                }
            }
        });
        this.tv_earn_money_index = ((TextView) this.contentView.findViewById(2131099960));
        this.tv_register_people_count = ((TextView) this.contentView.findViewById(2131100102));
        this.tv_zhuanqian_percent = ((TextView) this.contentView.findViewById(2131100103));
        this.lin_paking_28 = ((RelativeLayout) this.contentView.findViewById(2131100104));
        this.lin_canda_28 = ((RelativeLayout) this.contentView.findViewById(2131100107));
        Bitmap localBitmap = BitmapFactory.decodeResource(getResources(), 2130837636);
        int i = localBitmap.getWidth();
        int j = localBitmap.getHeight() * (-10 + getResources().getDisplayMetrics().widthPixels / 2) / i;
        ViewGroup.LayoutParams localLayoutParams1 = this.lin_paking_28.getLayoutParams();
        localLayoutParams1.height = j;
        this.lin_paking_28.setLayoutParams(localLayoutParams1);
        this.lin_canda_28.setLayoutParams(localLayoutParams1);
        this.img_scroll_left = ((ImageView) this.contentView.findViewById(2131100110));
        this.img_scroll_left.setVisibility(8);
        this.img_scroll_right = ((ImageView) this.contentView.findViewById(2131100111));
        this.img_scroll_right.setVisibility(8);
        this.img_wanfa_paking = ((ImageView) this.contentView.findViewById(2131100106));
        this.img_wanfa_canada = ((ImageView) this.contentView.findViewById(2131100109));
        ViewGroup.LayoutParams localLayoutParams2 = this.img_wanfa_paking.getLayoutParams();
        localLayoutParams2.width = (this.screenWidth / 2);
        this.img_wanfa_paking.setLayoutParams(localLayoutParams2);
        this.img_wanfa_canada.setLayoutParams(localLayoutParams2);
        this.lin_paking_28.setOnClickListener(this);
        this.lin_canda_28.setOnClickListener(this);
        this.img_scroll_left.setOnClickListener(this);
        this.img_scroll_right.setOnClickListener(this);
        this.img_wanfa_paking.setOnClickListener(this);
        this.img_wanfa_canada.setOnClickListener(this);
    }

    private void initDotsAndMakeStart() {
        if ((this.pic_ids != null) && (this.pic_ids.size() > 0)) {
            if (this.timerTask != null) {
                this.timerTask.cancel();
                this.timerTask = null;
            }
            if (this.layout_dots != null)
                this.layout_dots.removeAllViews();
            if ((this.dot_view != null) && (this.dot_view.size() != 0))
                this.dot_view.clear();
        }
        for (int i = 0; ; i++) {
            if (i >= this.pic_ids.size()) {
                this.pagerAdapter.pic_ids = this.pic_ids;
                this.pagerAdapter.notifyDataSetChanged();
                this.timerTask = new AdvTimerTask();
                this.timer.scheduleAtFixedRate(this.timerTask, 0L, 4000L);
                return;
            }
            ImageView localImageView = new ImageView(getActivity());
            localImageView.setImageDrawable(getActivity().getResources().getDrawable(2130838124));
            this.dot_view.add(localImageView);
            this.layout_dots.addView(localImageView);
        }
    }

    public void getDatasFromServer() {
        getNumberInfo();
        getBanners();
    }

    public void onActivityCreated(Bundle paramBundle) {
        super.onActivityCreated(paramBundle);
    }

    public void onClick(View paramView) {
        switch (paramView.getId()) {
            case 2131100105:
            case 2131100108:
            default:
                return;
            case 2131100104:
                if (!CustomApplication.app.isLogin) {
                    MainActivity.mainActivity.showLoginPop();
                    return;
                }
                Intent localIntent4 = new Intent(getActivity(), DaTingActivity.class);
                localIntent4.putExtra("parentid", "1");
                localIntent4.putExtra("lotteryid", "1");
                startActivity(localIntent4);
                return;
            case 2131100107:
                if (!CustomApplication.app.isLogin) {
                    MainActivity.mainActivity.showLoginPop();
                    return;
                }
                Intent localIntent3 = new Intent(getActivity(), DaTingActivity.class);
                localIntent3.putExtra("parentid", "34");
                localIntent3.putExtra("lotteryid", "3");
                LogUtils.i(this.TAG, "canadaRoomId:" + this.canadaRoomId);
                LogUtils.i(this.TAG, "canadaLotteryId:" + this.canadaLotteryId);
                startActivity(localIntent3);
                return;
            case 2131100106:
                Intent localIntent2 = new Intent(getActivity(), WanFaActivity.class);
                localIntent2.putExtra("instructionType", "1");
                startActivity(localIntent2);
                return;
            case 2131100109:
        }
        Intent localIntent1 = new Intent(getActivity(), WanFaActivity.class);
        localIntent1.putExtra("instructionType", "2");
        startActivity(localIntent1);
    }

    public void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        fragment = this;
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        this.contentView = paramLayoutInflater.inflate(R.layout.fragment_index, null);
        this.screenWidth = CustomApplication.app.displayMetrics.widthPixels;
        this.screenHeight = CustomApplication.app.displayMetrics.heightPixels;
        init();
        getBanners();
        return this.contentView;
    }

    public void onDestroy() {
        super.onDestroy();
        this.isRunning = false;
        if (this.timer != null) {
            this.timer.cancel();
            this.timer = null;
        }
        if (this.timerTask != null) {
            this.timerTask.cancel();
            this.timerTask = null;
        }
    }

    public void onResume() {
        super.onResume();
        getDatasFromServer();
    }

    class AdvTimerTask extends TimerTask {
        AdvTimerTask() {
        }

        public void run() {
            IndexFragment.this.handler.sendEmptyMessage(0);
        }
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.tabIndex.IndexFragment
 * JD-Core Version:    0.6.2
 */